import 'package:efood_multivendor/controller/transaction_controller.dart';
import 'package:efood_multivendor/data/model/response/transaction_model.dart';
import 'package:efood_multivendor/helper/date_converter.dart';
import 'package:efood_multivendor/helper/size_config.dart';
import 'package:efood_multivendor/util/dimensions.dart';
import 'package:efood_multivendor/util/styles.dart';
import 'package:efood_multivendor/view/base/no_data_screen.dart';
import 'package:efood_multivendor/view/screens/wallet/widget/transaction_shimmer.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class TransactionView extends StatelessWidget {
  final List<String>? transactionType;

  const TransactionView({Key? key, this.transactionType}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: GetBuilder<TransactionController>(builder: (transactionController) {
        int length = 0;
        List<TransactionModel>? transactionList =
            transactionController.historyTransactionList;
        if (transactionController.historyTransactionList != null) {
          length = transactionController.historyTransactionList!.length;
        }

        return transactionList != null
            ? transactionList.length > 0
                ? SizedBox(
                    width: Dimensions.WEB_MAX_WIDTH,
                    child: SingleChildScrollView(
                      child: Column(
                        children: [
                          ListView.separated(
                            separatorBuilder:
                                (BuildContext context, int index) => Padding(
                              padding: EdgeInsets.only(left: 3.w, right: 2.w),
                              child: Divider(
                                color: Theme.of(context).disabledColor,
                                height: Dimensions.PADDING_SIZE_LARGE,
                              ),
                            ),
                            padding:
                                EdgeInsets.all(Dimensions.PADDING_SIZE_SMALL),
                            itemCount: length > 7 ? 7 : length,
                            physics: NeverScrollableScrollPhysics(),
                            shrinkWrap: true,
                            itemBuilder: (context, index) {
                              if (index != transactionList.length) {
                                return Padding(
                                  padding: EdgeInsets.only(right: 2.w),
                                  child: Container(
                                    child: Column(children: [
                                      Row(children: [
                                        SizedBox(
                                            width:
                                                Dimensions.PADDING_SIZE_SMALL),
                                        Expanded(
                                          child: Column(
                                              crossAxisAlignment:
                                                  CrossAxisAlignment.start,
                                              children: [
                                                Row(children: [
                                                  SizedBox(
                                                      width: Dimensions
                                                          .PADDING_SIZE_EXTRA_SMALL),
                                                  Text(
                                                      transactionList[index]
                                                              .transactionType
                                                              ?.tr ??
                                                          '',
                                                      style: sfMedium.copyWith(
                                                          fontSize: Dimensions
                                                              .fontSizeDefault))
                                                ]),
                                                SizedBox(height: 1.5.h),
                                                Padding(
                                                  padding: EdgeInsets.only(
                                                      left: 1.5.w),
                                                  child: Text(
                                                    DateConverter
                                                        .convertUtcToEat(
                                                            transactionList[
                                                                        index]
                                                                    .createdAt ??
                                                                ''),
                                                    style: sfRegular.copyWith(
                                                        color: Theme.of(context)
                                                            .disabledColor,
                                                        fontSize: Dimensions
                                                            .fontSizeSmall),
                                                  ),
                                                ),
                                              ]),
                                        ),
                                        SizedBox(
                                            width:
                                                Dimensions.PADDING_SIZE_SMALL),
                                        Expanded(
                                          child: Column(
                                              crossAxisAlignment:
                                                  CrossAxisAlignment.end,
                                              children: [
                                                Padding(
                                                    padding: EdgeInsets.only(
                                                        right: 0.5.w),
                                                    child:
                                                        transactionList[index]
                                                                    .debit! >
                                                                0
                                                            ? Text(
                                                                '- ${transactionList[index].debit} Pts',
                                                                style: TextStyle(
                                                                    fontSize:
                                                                        Dimensions
                                                                            .fontSizeDefault,
                                                                    color: Colors
                                                                        .red),
                                                              )
                                                            : Text(
                                                                '+ ${transactionList[index].credit} Pts',
                                                                style: TextStyle(
                                                                    fontSize:
                                                                        Dimensions
                                                                            .fontSizeDefault,
                                                                    color: Colors
                                                                        .green),
                                                              )),
                                              ]),
                                        ),
                                      ]),
                                    ]),
                                  ),
                                );
                              } else {
                                return SizedBox(
                                  height: 10.h,
                                );
                              }
                            },
                          ),
                        ],
                      ),
                    ),
                  )
                : NoDataScreen(
                    text: 'no_transaction'.tr,
                    isTransaction: true,
                  )
            : TransactionShimmer(
                transactionController: transactionController,
                fromView: true,
              );
      }),
    );
  }
}
